package stanford.com.balldating;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by KAI on 2017/6/14.
 */

public class FriendsListAdapter extends BaseAdapter{
    Context context;
    LayoutInflater lfInflater;
    List<User> list;

    public FriendsListAdapter(Context context,List<User> list){
        this.context=context;
        this.list=list;
        lfInflater = LayoutInflater.from(this.context);
    }

    @Override
    public User getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        User friend=list.get(position);
        ViewHolder holder= null;
        if(null==convertView){
            convertView = lfInflater.inflate(R.layout.friends_listview_item, null);
            holder = new ViewHolder();
            holder.raiv_faceico=(ImageView)convertView.findViewById(R.id.friend_raiv_faceico);
            holder.nickname= (TextView)convertView.findViewById(R.id.friend_nickname);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }

        holder.raiv_faceico.setBackgroundResource(R.drawable.male);
        holder.nickname.setText(friend.getname());

        return convertView;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    class ViewHolder{
        ImageView raiv_faceico;//头像
        TextView nickname;
    }
}
